//
//  BCPaySucView.m
//  BangcaiBuy
//
//  Created by lsy on 16/7/5.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCPaySucView.h"

@interface BCPaySucView ()
{
    UIView *headView;
    UILabel *headLab;
    UIImageView *headImg;
    
    UILabel *littlePrice;
    UILabel *priceLab;
    UILabel *priceInfoLab;
    UILabel *priceLine;
    
    UILabel *orderLab;
    UILabel *ordNumLab;
    UILabel *orderLine;
    
    UILabel *timeLab;
    UILabel *timeInfoLab;
    UILabel *timeLine;
    
    UILabel *payStyle;
    UILabel *payStyInfo;
    
    UIView *midLine;
    
    UIImageView *logoImg;
    
    
}
@end

@implementation BCPaySucView

- (void)createView
{
    headView = [[UIView alloc] init];
    headView.backgroundColor = BangcaiGreen;
    headLab = [[UILabel alloc] init];
    headLab.text = @"支付成功";
    headLab.font = [UIFont systemFontOfSize:24];
    headLab.textColor = [UIColor whiteColor];
    headImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"成功"]];
   
    [headView addSubview:headImg];
    [headView addSubview:headLab];
    
    priceLab = [[UILabel alloc] init];
    priceInfoLab = [[UILabel alloc] init];
    priceLine = [[UILabel alloc] init];
    littlePrice = [[UILabel alloc] init];
    priceLab.textColor = [UIColor colorWithRed:0.998  green:0.402  blue:0.005 alpha:1];
    priceLab.font = [UIFont systemFontOfSize:60];
    NSArray * arr = [BCOrderViewManager readStuffFromOrder];
    
    __block CGFloat price = 0;
    
    [arr enumerateObjectsUsingBlock:^(ORDER  * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        price += obj.price.floatValue * obj.count.integerValue;
    }];
    priceLab.text =[NSString stringWithFormat:@"%.2f", price];
    priceLab.textAlignment = NSTextAlignmentCenter;
    priceLab.backgroundColor = [UIColor whiteColor];
    littlePrice.textColor = [UIColor colorWithRed:0.998  green:0.402  blue:0.005 alpha:1];
    littlePrice.text = @"¥";
    littlePrice.font = [UIFont systemFontOfSize:40];
    priceInfoLab.text = @"付款总额";
    priceInfoLab.font = [UIFont systemFontOfSize:14];
    priceInfoLab.textColor = [UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    priceLine = [[UILabel alloc] init];
    priceLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];
    
    orderLab = [[UILabel alloc] init];
    ordNumLab = [[UILabel alloc] init];
    orderLine = [[UILabel alloc] init];
    orderLab.text = @"订单编号";
    orderLab.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    orderLab.font = [UIFont systemFontOfSize:14];
    ordNumLab.text = @"2016060620411030005";
    ordNumLab.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    ordNumLab.font = [UIFont systemFontOfSize:14];
    orderLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];
    
    timeLab = [[UILabel alloc] init];
    timeInfoLab = [[UILabel alloc] init];
    timeLine = [[UILabel alloc] init];
    timeLab.text = @"交易时间";
    timeLab.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    timeLab.font = [UIFont systemFontOfSize:14];
    timeInfoLab.text = @"2016-06-24 17:30";
    timeInfoLab.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    timeInfoLab.font = [UIFont systemFontOfSize:14];
    timeLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];
    
    payStyle = [[UILabel alloc] init];
    payStyInfo = [[UILabel alloc] init];
    midLine = [[UILabel alloc] init];
    payStyle.text = @"交易时间";
    payStyle.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    payStyle.font = [UIFont systemFontOfSize:14];
    payStyInfo.text = @"2016-06-24 17:30";
    payStyInfo.textColor =[UIColor colorWithRed:0.557  green:0.557  blue:0.557 alpha:1];
    payStyInfo.font = [UIFont systemFontOfSize:14];
    midLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];
    
    logoImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LOGO"]];
    
    self.checkOrder = [UIButton buttonWithType:UIButtonTypeSystem];
    self.backHome = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.checkOrder setTitle:@"查看订单" forState:UIControlStateNormal];
    [self.backHome setTitle:@"回首页" forState:UIControlStateNormal];
    self.checkOrder.layer.borderWidth = 1;
    self.checkOrder.layer.borderColor = [UIColor colorWithRed:0.816  green:0.816  blue:0.816 alpha:1].CGColor;
    [self.checkOrder setTintColor:[UIColor blackColor]];
    self.backHome.backgroundColor = BangcaiGreen;
    [self.backHome setTintColor:[UIColor whiteColor]];
    
    
    [self addSubview:headView];
    
    [self addSubview:priceLab];
    [self addSubview:priceInfoLab];
    [self addSubview:priceLine];
    [self addSubview:littlePrice];
    
    [self addSubview:orderLab];
    [self addSubview:ordNumLab];
    [self addSubview:orderLine];
    
    [self addSubview:timeLab];
    [self addSubview:timeInfoLab];
    [self addSubview:timeLine];
    
    [self addSubview:payStyle];
    [self addSubview:payStyInfo];
    [self addSubview:midLine];
    
    [self addSubview:logoImg];
    [self addSubview:self.checkOrder];
    [self addSubview:self.backHome];
    [self getLayOut];

}

- (void)getLayOut
{
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    
    [headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.centerY.mas_equalTo(0);
        make.height.and.width.mas_equalTo(42);
        
    }];
    
    [headLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headImg.mas_right).with.offset(20);
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(0);
    }];
    
    [priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(headView.mas_bottom).with.offset(40);
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    
    [littlePrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(priceLab.mas_left).with.offset(-10);
        make.bottom.mas_equalTo(priceLab.mas_bottom).with.offset(-2);
        make.height.mas_equalTo(40);
        
    }];
    
    [priceInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(priceLab.mas_bottom).with.offset(12);
        make.height.mas_equalTo(14);
    }];
    
    [priceLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(priceInfoLab.mas_bottom).with.offset(12);
    }];
    
    [orderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(priceLine.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    
    [ordNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(orderLab.mas_height);
        make.top.mas_equalTo(orderLab.mas_top);
        
    }];
    
    [orderLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(orderLab.mas_bottom);
    }];
    
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(orderLine.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    
    [timeInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(timeLab.mas_height);
        make.top.mas_equalTo(timeLab.mas_top);
        
    }];
    
    [timeLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(timeInfoLab.mas_bottom);
    }];
    
    [payStyle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(timeLab.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    
    [payStyInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(payStyle.mas_height);
        make.top.mas_equalTo(payStyle.mas_top);
        
    }];
    
    [midLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(10);
        make.top.mas_equalTo(payStyInfo.mas_bottom);
    }];

    [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(midLine.mas_bottom).with.offset(40);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(150);
    }];
    
    [self.backHome mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH /2);
        make.bottom.mas_equalTo(-64);
        make.height.mas_equalTo(50);
    }];
    
    [self.checkOrder mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH /2);
        make.bottom.mas_equalTo(-64);
        make.height.mas_equalTo(50);

    }];
    
}

@end
